<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<script src="js/mui.js"></script>
		<script src="./utils/myRequest.js"></script>
		<script type="text/javascript">
			mui.init();
			mui.plusReady(function(){
				//跳转到新用户页面
				var newUser = document.getElementById('newUser');
				newUser.addEventListener("tap",function(){
					// plus.nativeUI.toast('跳转到新用户');
					plus.webview.open("./register.html","register.html");
				});
				
					
				document.getElementById("test").addEventListener("tap",function(){
					//跳转到首页
					plus.webview.open("./index.html","index.html");
					//关闭当前页面
					plus.webview.currentWebview().close();
				});
				
				//登录成功后跳转到首页
				document.getElementById("btnLogin").addEventListener("tap",function(){
					var username = document.getElementById("username").value;
					var password = document.getElementById("password").value; 
					
					console.log("username = " + username + ", password = " + password);
					
					var param = {
							username,
							password
						};
						
					// console.log(param);
					
					request.ajax({
						url : "/websocket/user/login",
						data : param,
						type : "post",
						success : function(resp){
							if(resp.code == 20000){
								
								//提示用户登录成功
								plus.nativeUI.toast(resp.message);
								//保存当前用户到本地中
								store.setItem(JSON.stringify(resp.data.user));
								//跳转到首页
								plus.webview.open("./index.html","index.html");
								//关闭当前页面
								plus.webview.currentWebview().close();
								
							}else{
								plus.nativeUI.toast(resp.message);
							}
						}
					});
				});
				
				//跳转到修改密码页面
				// var resetPwd = document.getElementById("resetPwd");
				// resetPwd.addEventListener("tap",function(){
				// 	plus.webview.open("./reset.html","reset.html");
				// },{passive: false });
			})
		</script>
	</head>

	<body>
		<!-- <h1>登录页面</h1> -->
		<!-- 标题栏 -->
		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">登录</h1>
		</header>
		<!-- 表单登录 -->
		<div style="margin-top: 100px;text-align: center;">
			<!-- 头像 -->
			<img src="./img/tou.jpg" style="width: 100px;border-radius: 50%;margin-bottom: 10px;" />
			<!-- 表单 -->
			<form class="mui-input-group">
			    <div class="mui-input-row">
			        <label>用户名</label>
			    <input type="text" class="mui-input-clear"  id="username" placeholder="请输入用户名">
			    </div>
			    <div class="mui-input-row">
			        <label>密码</label>
			        <input type="password" id="password"  class="mui-input-password" placeholder="请输入密码">
			    </div>
			    <div class="mui-button-row">
			        <button type="button" id="btnLogin" class="mui-btn mui-btn-primary" >登录</button>
			        <button type="button" class="mui-btn mui-btn-danger" >取消</button>
			    </div>
			</form>
			<!-- 新用户注册/忘记密码 -->
			<hr  />
			<div>
				<a id="newUser">新用户</a> &nbsp;|&nbsp; <a id="resetPwd">忘记密码</a> &nbsp;|&nbsp; <a id="test">测试账号</a>
			</div>
		</div>
	</body>

</html>
